package com.central.dataManage.controller;


import com.central.common.annotation.RequiredPermission;
import com.central.common.constant.PermissionConstants;
import com.central.common.model.Result;
import com.central.dataManage.service.IDatasourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.sql.SQLException;

/**
 * @author Tindy
 * @date 2021/6/24
 * @describe
 */
@Slf4j
@RestController
@Api(tags = "系统管理员模块api")
@RequestMapping(value = "/admin")
public class AdminController {

    @Autowired
    private IDatasourceService datasourceService;

    @ApiOperation(value = "创建用户库")
    @GetMapping("/createUserDatabase")
    @RequiredPermission(PermissionConstants.SYS_ADMIN)
    public Result createUserDatabase(String username) throws SQLException {
        return datasourceService.createUserDatabase(username);
    }

    @ApiOperation(value = "创建项目库")
    @GetMapping("/createProDatabase")
    @RequiredPermission(PermissionConstants.SYS_ADMIN)
    public Result createProDatabase(String proName) throws SQLException, IOException {
        return datasourceService.createProDatabase(proName);
    }

    @ApiOperation(value = "设置项目/个人库容量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名（用户名和项目id选填一个）", required = false, dataType = "String"),
            @ApiImplicitParam(name = "proName", value = "项目名", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "size", value = "库容量 单位G", required = true, dataType = "Long")
    })
    @GetMapping("/setDbSize")
    @RequiredPermission(PermissionConstants.SYS_ADMIN)
    public Result setDbSize(String username,String proName,Long size) throws SQLException {
        return datasourceService.setDbSize(username,proName,size);
    }


}
